<template>
	<view class="content">
		<view class="concern">
			<view class="concern-list">
				<image :src="$u.fileBaseUrl+homeList.avatar" mode="aspectFill"></image>
				<view class="concern-center">
					<text>{{homeList.nickname}}</text>
					<!-- <text>喜欢旅行，热爱生活</text> -->
				</view>
			</view>
			<button @click="getfocusOrCancelFocusUser(homeList)">取消关注</button>
		</view>
		<view class="concern-content">
			<view class="concern-trends">
				她的动态
			</view>
			<view class="concern-content-list" v-for="(item,index) in MomentsgeList" :key="index"
				@click="gohomepageDetail(item.id)">
				<!-- <view class="top">
					<image :src="$u.fileBaseUrl+item.avatar" mode="aspectFill"></image>
					<view class="top-left">
						<view>{{item.nickname}}</view>
						<view>{{item.createTime}}</view>
					</view>
				</view> -->
				<image class="image"
					:src="item.images ?$u.fileBaseUrl+item.images.split(',')[0] :'../../static/images/index/zwtp.png' "
					mode="aspectFill">
				</image>
				<view class="title">
					{{item.title}}
				</view>
				<view class="bottom">
					<text>好看好看哈哈</text>
					<view>
						<uni-icons type="chat" size="30" color="#666666"></uni-icons>
						<text>{{item.commentNum || 0}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				homeList: {},
				MomentsgeList: [],
				page: {
					pageNum: 1,
					pageSize: 10
				},
				total: 0
			};
		},
		onLoad(options) {
			this.focusUid = options.focusUid
		},
		onShow() {
			this.gethomepage(this.focusUid)
			this.getqueryFocusUserMomentsge(this.focusUid)
		},
		// 下拉刷新
		onPullDownRefresh() {
			// 刷新数据的逻辑
			this.page.pageNum = 1
			this.page.pageSize = 10
			this.getqueryFocusUserMomentsge(this.focusUid)
			// 模拟异步操作
			setTimeout(() => {
				// 刷新完成后，结束下拉刷新
				uni.stopPullDownRefresh();
			}, 1000);
		},
		// 上拉加载
		onReachBottom() {
			this.loadMore();
			// this.getqueryFocusUserMomentsge()
		},
		methods: {
			loadMore() {

				if (this.MomentsgeList.length >= this.total) {
					uni.showToast({
						title: '没有更多动态了',
						icon: "none"
					});
					return;
				}
				this.page.pageNum += 1;
				uni.showLoading({
					title: '加载中...'
				});

				this.getqueryFocusUserMomentsge(this.focusUid).then(() => {
					uni.hideLoading();
				}).catch(error => {
					console.error('加载更多数据时出错:', error);
					uni.hideLoading();
					uni.showToast({
						title: '加载失败，请重试',
						icon: 'none'
					});
				});
			},
			// 获取关注用户信息
			async gethomepage(focusUid) {
				let res = await this.$u.api.gethomepage({
					focusUid: focusUid
				})
				if (res.code == 200) {
					this.homeList = res.data
				}
			},
			// 获取关注用户的动态
			async getqueryFocusUserMomentsge(focusUid) {
				let res = await this.$u.api.getqueryFocusUserMomentsge({
					uid: focusUid,
					pageNum: this.page.pageNum,
					pageSize: this.page.pageSize
				})
				if (res.code == 200) {
					// 如果是第一页，直接替换数据
					if (this.page.pageNum == 1) {
						this.MomentsgeList = res.rows;
					} else {
						// 如果不是第一页，追加数据
						this.MomentsgeList = [...this.MomentsgeList, ...res.rows];
					}
					this.total = res.total;
				}
			},
			// 跳转到动态详情页面
			gohomepageDetail(id) {
				uni.navigateTo({
					url: `/packagesIndex/pages/guideDetails/guideDetails?id=${id}`
				})
			},
			// 取消关注
			async getfocusOrCancelFocusUser(homeList) {
				let res = await this.$u.api.getfocusOrCancelFocusUser({
					focusId: homeList.uid,
					type: 0,
				})
				if (res.code == 200) {
					this.$u.toast('取消关注成功')
					this.getuserFocus()
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		min-height: 95vh;

		.concern {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #fff;
			padding: 30rpx;
			box-sizing: border-box;

			.concern-list {
				display: flex;
				align-items: center;

				image {
					width: 96rpx;
					height: 96rpx;
					margin-right: 20rpx;
					border-radius: 50%;
				}

				.concern-center {
					text {
						display: block;

						&:nth-child(1) {
							font-weight: 600;
							font-size: 32rpx;
							color: #000000;
						}

						&:nth-child(2) {
							font-size: 28rpx;
							color: #666666;
						}
					}
				}
			}

			button {
				font-size: 28rpx;
				color: #666666;
				padding: 10rpx 20rpx;
				background-color: #EFEFEF;
				border-radius: 10rpx;
				box-sizing: border-box;
			}
		}

		.concern-content {
			background-color: #fff;
			// margin-top: 20rpx;
			padding: 0 30rpx;
			box-sizing: border-box;

			.concern-trends {
				font-weight: 700;
				font-size: 32rpx;
				margin: 20rpx 0;
			}

			.concern-content-list {
				margin: 30rpx 0;

				.top {
					display: flex;
					align-items: center;

					image {
						width: 96rpx;
						height: 96rpx;
						margin-right: 20rpx;
						border-radius: 50%;
					}
				}

				.image {
					width: 98%;
					margin: 1% 1% 3% 1%;
					border-radius: 20rpx;
				}

				.title {
					font-weight: 700;
					font-size: 32rpx;
				}

				.bottom {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 20rpx 0;
					color: #666666;

					view {
						display: flex;
						align-items: center;
					}
				}
			}
		}
	}
</style>